﻿using AutoMapper;
using MediatR;
using Traceability.Commont.Domains;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.EnterpriseFiles
{
    public class EnterpriseCreateHander : IRequestHandler<EnterpriseCreateCommand, Resqults>
    {
        private readonly IBateRepository<Enterprises> enter;
        private readonly IMapper mapper;

        public EnterpriseCreateHander(IBateRepository<Enterprises> enter, IMapper mapper)
        {
            this.enter = enter;
            this.mapper = mapper;
        }

        public async Task<Resqults> Handle(EnterpriseCreateCommand request, CancellationToken cancellationToken)
        {
            try
            {

                Resqults res = new Resqults() { Code = 0 };
                Enterprises info = mapper.Map<Enterprises>(request);
                res.Code =await enter.Add(info);
                if (res.Code > 0)
                {
                    res.Messges = "添加成功";
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
